/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package onpu_dms_xls.kernel.common;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.beans.*;

/**
 *
 * @author snbm
 */
public class ProgressBar extends JFrame {

    private JProgressBar progressBar;
    private JLabel taskOutput;

    public ProgressBar() {
        super();
        progressBar = new JProgressBar(0, 100);
        progressBar.setValue(0);
        progressBar.setStringPainted(true);

        taskOutput = new JLabel();

        JPanel panel = new JPanel(new GridLayout(2, 1));

        panel.add(progressBar);
        panel.add(taskOutput);
        add(panel);


        setVisible(true);
        Toolkit tk = Toolkit.getDefaultToolkit();
        Dimension screen = tk.getScreenSize();
        int screenH = screen.height;
        int screenW = screen.width;
        setSize(250, 100);
        setLocation(screenW/2, screenH / 2);
        setTitle("Генерація і зберігання XLS документу...");
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
        //Create the demo's UI.

    }
    private int progressInPercents;
    private String text;

    public void setProgressAndText(int progressInPercents, String text) {
        if (progressInPercents > 100) {
            setCursor(null);
//            this.setVisible(false);

            return;
        }

        this.progressInPercents = progressInPercents;
        this.text = text;

        this.repaint();
    }

    @Override
    public void paint(Graphics g) {
        
        progressBar.setValue(progressInPercents);
        taskOutput.setText(text);
    }
}
